//package com.moyun.websocket.disruptor;
//
//
//import com.lmax.disruptor.RingBuffer;
//import com.lmax.disruptor.dsl.Disruptor;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.concurrent.Executor;
//import java.util.concurrent.Executors;
//
///**
// * Created by kl on 2018/8/24.
// * Content :Disruptor 环形队列
// */
//@Component
//public class LoggerDisruptorQueue {
//
//    private Executor executor = Executors.newCachedThreadPool();
//
//    // The factory for the event  1. 获取系统中每个事件的工厂
//    private FileLoggerEventFactory fileLoggerEventFactory = new FileLoggerEventFactory();
//
//    // Specify the size of the ring buffer, must be power of 2. 指定环形缓冲区的大小，必须是 2 的幂。
//    private int bufferSize = 2 * 1024;
//
//    // Construct the Disruptor
//
//    private Disruptor<FileLoggerEvent> fileLoggerEventDisruptor = new Disruptor<>(fileLoggerEventFactory, bufferSize, executor);
//
//    private static RingBuffer<FileLoggerEvent> fileLoggerEventRingBuffer;
//
//    @Autowired
//    LoggerDisruptorQueue(FileLoggerEventHandler fileLoggerEventHandler) {
//        fileLoggerEventDisruptor.handleEventsWith(fileLoggerEventHandler);
//        fileLoggerEventRingBuffer = fileLoggerEventDisruptor.getRingBuffer();
//        fileLoggerEventDisruptor.start();
//    }
//
//
//    public static void publishEvent(String log) {
//        if(fileLoggerEventRingBuffer == null) return;
//        long sequence = fileLoggerEventRingBuffer.next();  // Grab the next sequence 1.抓取下一个序列
//        try {
//            FileLoggerEvent event = fileLoggerEventRingBuffer.get(sequence); // Get the entry in the Disruptor 2.获取 Disruptor 中的条目
//            // for the sequence 3.对于序列
//            event.setLog(log);  // Fill with data 4.填充数据
//        } finally {
//            fileLoggerEventRingBuffer.publish(sequence); // 发布事件
//        }
//    }
//
//}
